﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class MainListingControl : System.Web.UI.UserControl
{
    private int listId;

    public int listingId
    {
        get
        {
            return listId;
        }
        set
        {
            listId = value;
            setValues(listId);
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        //setValues(listingId);

    }

    public void setValues(int listingId)
    {
        DataTable dtListing = new DataTable();
        dtListing = BuddyAgentDAL.GetParticularListingInfo(listingId);
        linkText.Text = dtListing.Rows[0]["ListingHeader"].ToString();
        linkText.PostBackUrl = "~/ParticularListingInformation.aspx?ListingId=" + dtListing.Rows[0][0].ToString();
        lblParameters.Text = dtListing.Rows[0]["NoOfBedrooms"].ToString() + " BR, " + dtListing.Rows[0]["NoOfBathrooms"].ToString() + " BA, " +
            dtListing.Rows[0]["SqFeets"].ToString() + " Sq.ft, " + dtListing.Rows[0]["ListingSubcategorey"].ToString() + ", " +
            dtListing.Rows[0]["Area"].ToString() + ", " + dtListing.Rows[0]["City"].ToString();
        if (dtListing.Rows[0][11].ToString().Length >= 100)
            lblDesc.Text = dtListing.Rows[0][11].ToString().Substring(0, 99) + "....";
        else
            lblDesc.Text = dtListing.Rows[0][11].ToString();

        DataTable dtAgent = new DataTable();
        dtAgent = BuddyAgentDAL.GetBuddyAgentInfo(Convert.ToInt32(dtListing.Rows[0][1]));
        lblPostedBy.Text = dtAgent.Rows[0][1].ToString();
        imgUser.ImageUrl = dtAgent.Rows[0][2].ToString();

        DataTable dtPhotos = new DataTable();
        dtPhotos = BuddyAgentDAL.GetListingAllPhotos(listingId);
        if (dtPhotos.Rows.Count != 0)
        {
            imgHouse.ImageUrl = "~/" + dtPhotos.Rows[0][1].ToString();
        }
        else
        {
            imgHouse.ImageUrl = "~/Image/missing_housing.gif";
        }
        string body = "<div id='fb-root'></div><script src='http://connect.facebook.net/en_US/all.js#xfbml=1'></script><fb:comments href=\"www.buddyAgent.com/default.aspx?id=" + listingId + "\" num_posts=\"2\" width=\"350\"></fb:comments>";
        //string body = "<fb:like href=\"www.buddyAgent.com/default.aspx?id="+listingId+" send=\"false\" width=\"380\" show_faces=\"true\" font=\"\"></fb:like>";
        RectFacebookComments.InnerHtml = body;
        //RectFacebookComments.Visible = false;
        //btnComment.Attributes.Add("onclick", "javascript:showComments(this);");
    }

}